package com.bootdo.system.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.utils.DateUtils;
import com.bootdo.system.domain.TbWxmenu;
import com.bootdo.system.domain.TbWxmenuExample;
import com.bootdo.system.domain.TbWxmenuExample.Criteria;
import com.bootdo.system.mapper.TbWxmenuMapper;
import com.bootdo.system.service.WxMenuService;


@Service
public class WxMenuServiceImpl implements WxMenuService{
	
	@Autowired
    private TbWxmenuMapper wm;

	@Override
	public List<TbWxmenu> list(Long userId,List<Long> userIds) {
		TbWxmenuExample tbWxmenuExample = new TbWxmenuExample();
		Criteria createCriteria = tbWxmenuExample.createCriteria();
		if(userIds != null && userIds.size() > 0) {
			createCriteria.andAdminIdIn(userIds);
		}
		if(userId != null) {
			createCriteria.andAdminIdEqualTo(userId);
		}
		return wm.selectByExample(tbWxmenuExample);
	}

	@Override
	public int insert2update(TbWxmenu table) {
		int res=0;
		if(table != null) {
			Integer id = table.getId();
			if(id != null) {
				table.setUpdatetime(DateUtils.format(new Date()));
				res=wm.updateByPrimaryKeySelective(table);
			}else {
				table.setCreatetime(DateUtils.format(new Date()));
				res=wm.insertSelective(table);
			}
		}
		return res;
	}

	@Override
	public TbWxmenu getById(Integer id) {
		return wm.selectByPrimaryKey(id);
	}

	@Override
	public int remove(Integer id) {
		return wm.deleteByPrimaryKey(id);
	}

	@Override
	public int batchremove(Integer[] gzhIds) {
		int res=0;
		if(gzhIds.length > 0) {
			for (int i = 0; i < gzhIds.length; i++) {
				res=wm.deleteByPrimaryKey(gzhIds[i]);
			}
		}
		return res;
	}

	@Override
	public TbWxmenu selectByUserId(Integer appId) {
		TbWxmenuExample tbWxmenuExample = new TbWxmenuExample();
		Criteria createCriteria = tbWxmenuExample.createCriteria();
		createCriteria.andAdminIdEqualTo(Long.valueOf(appId));
		List<TbWxmenu> selectByExample = wm.selectByExample(tbWxmenuExample);
		if(selectByExample.size() > 0) {
			return selectByExample.get(0);
		}
		return null;
	}

}
